﻿package com.eve.microworld.main;

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.Handler;

import com.eve.microworld.R;
import com.eve.microworld.common.activity.BaseActivity;
import com.eve.microworld.common.db.MoveDBRunnable;
import com.eve.microworld.common.view.ComDialogTools;

/**
 * 欢迎界面
 * 
 * @author Norsie
 * @create 12-11-29
 */
public class WelcomeActivity extends BaseActivity
{

    private Context mContext = WelcomeActivity.this;
    private final static int SPLASH_DISPLAY_LENGHT = 3000;// 延迟3秒

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome_main);
        // 判断设备当前是否具备SD卡，若是，正常执行程序，若否，提示用户，退出程序。
        if (android.os.Environment.getExternalStorageState().equals(
                android.os.Environment.MEDIA_MOUNTED))
        {
            // 复制数据库到sd卡
            new Thread(new MoveDBRunnable(this)).start();
        }
        else
        {
            // 提示用户，退出程序
            ComDialogTools.showConfirmDialog(mContext, "错误", "确定", null,
                    "SD卡被拔出，请插入SD卡后重试！", new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which)
                        {
                            // TODO Auto-generated method stub
                            WelcomeActivity.this.finish();
                        }
                    }, null);
        }

        //延迟进入登陆界面
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run()
            {
                gotoActivityAndFinish(mContext, LoginActivity.class);
            }

        }, SPLASH_DISPLAY_LENGHT);
    }

}
